package xidian.vlab.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xidian.vlab.domin.User.Teacher;
import xidian.vlab.dto.QueryDTO;
import xidian.vlab.dto.ResJsonDTO;
import xidian.vlab.dto.UserDTO;
import xidian.vlab.service.UserService;
import xidian.vlab.utils.ResUtil;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResJsonDTO login(@RequestBody UserDTO user){
        return userService.login(user);
    }
    @PostMapping("/adminLogin")
    public ResJsonDTO adminLogin(@RequestBody UserDTO user){
        return userService.adminLogin(user);
    }
    @GetMapping("/info")
    public ResJsonDTO getInfo(@RequestParam("Token")String Token){
        return userService.getInfo(Token);
    }
    @PostMapping("/logout")
    public ResJsonDTO logout(@RequestBody String Token){
        return userService.logout(Token);
    }
    
    @PostMapping("/teacher")
    public ResJsonDTO createTeacher(@RequestBody Teacher teacher){
        if (teacher == null) return ResUtil.ERROR("未提供参数");
        return userService.createTeacher(teacher);
    }

    @GetMapping("/teachers")
    public ResJsonDTO getAllTeacher(QueryDTO query){
        if (query == null) return ResUtil.ERROR("未提供参数");
        return userService.getAllTeacher(query);
    }
    @GetMapping("/students")
    public ResJsonDTO getAllStudent(QueryDTO query){
        if (query == null) return ResUtil.ERROR("未提供参数");
        return userService.getAllStudent(query);
    }
}